<?php
class Ab_ImageFactory{
	private $path;
	private $pathType=null;
	
	function __construct($path){
		$this->path=$path;
		if(!@getimagesize($this->path)){
			throw new Exception('The path '.$this->path.' is not a valid image.');
		}
	}
	
	function getImageType(){	
		//image		
		if(list($width, $height, $type, $attr) = @getimagesize($this->path)){			
			switch($type){
				//gif
				case '1':
					$this->pathType=new Ab_ImageGIF($this->path);
				break;
				//jpg
				case '2':
					$this->pathType=new Ab_ImageJPG($this->path);
				break;
				//png
				case '3':
					$this->pathType=new Ab_ImagePNG($this->path);
				break;
				default:
					throw new Exception('Unspported image type.');
			}			
		}
		
		return $this->pathType;
	}
	
}
?>
